﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;


namespace Comment_ajax
{
    /// <summary>
    /// bodyload 的摘要说明
    /// </summary>
    public class bodyload : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            System.Text.StringBuilder result = new System.Text.StringBuilder(1000);

            foreach (DataRow row in GetAllComment().Rows)
            {
                result.Append(row["userName"].ToString());
                //利用@标记昵称信息
                result.Append("@");

                result.Append(row["msg"].ToString());
                //利用|标记评论信息
                result.Append("|");
            }

            context.Response.Write(result.ToString());
        }

        private DataTable GetAllComment()
        {
            String strConn = System.Configuration.ConfigurationManager.ConnectionStrings["Comment_AjaxConnStr"].ConnectionString;
            using (SqlConnection conn = new SqlConnection(strConn))
            {
                using (SqlDataAdapter sda = new SqlDataAdapter("select * from T_Comments", conn))
                {
                    DataTable DT = new DataTable();
                    sda.Fill(DT);
                    return DT;
                }
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}